﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class DebugUtil
{
	[System.Diagnostics.Conditional( "UNITY_EDITOR" )]
	public static void Assert( bool condition )
	{
		Assert( condition, string.Empty, false );
	}

	[System.Diagnostics.Conditional( "UNITY_EDITOR" )]
	public static void Assert( bool condition, string assertString )
	{
		Assert( condition, assertString, false );
	}

	[System.Diagnostics.Conditional( "UNITY_EDITOR" )]
	public static void Assert( bool condition, string assertString, bool pauseOnFail )
	{
		if( !condition )
		{
			Debug.LogError( "assert failed! " + assertString );
			
			if( pauseOnFail )
				Debug.Break();
		}
	}
	
	private static Stack<long> tickStack = new Stack<long>();

	[System.Diagnostics.Conditional( "UNITY_EDITOR" )]
	public static void StartTimestamp()
	{
		long startTick = System.DateTime.Now.Ticks;
		tickStack.Push(startTick);
	}

	[System.Diagnostics.Conditional( "UNITY_EDITOR" )]
	public static void StopTimestamp(string text)
	{
		Assert(tickStack.Count > 0);
		long stopTick = System.DateTime.Now.Ticks;
		Debug.Log (text + (stopTick - tickStack.Pop()));
	}
}
